package com.wydexcel.generate.process;

import com.wydexcel.generate.properties.s.ExcelCommentProperties;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;

public class WydExcelCellCommentProcessImpl implements WydExcelCellCommentProcess {

    WydExcelRichTextProcess wydExcelRichTextProcess = new WydExcelRichTextProcessImpl();

    private CreationHelper creationHelper = null;

    @Override
    public Comment commentProcess(Row row, Cell cell, ExcelCommentProperties properties, boolean isBody) {

//        Comment comment2 = drawing.createCellComment(anchor);
//        RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
//        //apply custom font to the text in the comment
//        Font font = wb.createFont();
//        font.setFontName("Arial");
//        font.setFontHeightInPoints((short) 14);
//        font.setBold(true);
//        font.setColor(IndexedColors.RED.getIndex());
//        str2.applyFont(font);
//
//        comment2.setString(str2);
//        comment2.setAuthor("Apache POI");
//        comment2.setAddress(new CellAddress("C3"));
        if (null == properties) {
            return null;
        }
        //设置 批注
        if (null == creationHelper) {
            creationHelper = row.getSheet().getWorkbook().getCreationHelper();
        }

        Drawing<?> drawing = row.getSheet().createDrawingPatriarch();
        ClientAnchor anchor = creationHelper.createClientAnchor();
        Comment comment1 = drawing.createCellComment(anchor);
        XSSFRichTextString xssfRichTextString = wydExcelRichTextProcess.richTextProcess(row, cell, row.getSheet(), properties.getRichText(), isBody);
        comment1.setString(xssfRichTextString);
        comment1.setAuthor(properties.getAuthor());

//        font.setFontName("Arial");
//        font.setFontHeightInPoints((short) 14);
//        font.setBold(true);
//        font.setColor(IndexedColors.RED.getIndex());
        cell.setCellComment(comment1);
        return comment1;
    }
}
